﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ECCSystem.DataAccess
{
	class ClsEmailAppoint : DBObject 
    {
		public DataSet GetEmailAppoint()
		{
			return RunProcedure("sp_EmailAppoint_GetList", new IDataParameter[] { }, "EmailAppoint");
		}

		public void AddEmailAppoint(DateTime dtStartTime, DateTime dtEndTime, string strUserName, string strUserID, int intUserID, string strKeyID, string strCSKeyID)
        {
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@StartTime", SqlDbType.DateTime),
															 new SqlParameter("@EndTime", SqlDbType.DateTime),
															 new SqlParameter("@UserName", SqlDbType.NVarChar,1000),
															 new SqlParameter("@UserID", SqlDbType.VarChar,1000),
															 new SqlParameter("@CreateID", SqlDbType.Int),
															 new SqlParameter("@ID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@KeyID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@CS_KeyID", SqlDbType.UniqueIdentifier)};
			Guid guid = Guid.NewGuid();
			
			parameters[0].Value = dtStartTime;
			parameters[1].Value = dtEndTime;
			parameters[2].Value = strUserName;
			parameters[3].Value = strUserID;
			parameters[4].Value = intUserID;
			parameters[5].Value = guid;

			if (!(strKeyID != null ^ strKeyID != ""))
			{
				guid = new Guid(strKeyID);
				parameters[6].Value = guid;
			}
			else
			{
				parameters[6].Value = System.DBNull.Value;
			}

			if (!(strCSKeyID != null ^ strCSKeyID != ""))
			{
				guid = new Guid(strCSKeyID);
				parameters[7].Value = guid;
			}
			else
			{
				parameters[7].Value = System.DBNull.Value;
			}
			this.RunProcedure("sp_EmailAppoint_Add", parameters, "EmailAppoint");
        }

		public void DeleteEmailAppoint(string strID)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.UniqueIdentifier) };
			Guid guid = new Guid(strID);
			parameters[0].Value = guid;
			this.RunProcedure("sp_EmailAppoint_Delete", parameters, "EmailAppoint");
		}

		public void UpdateEmailAppoint(string strID, DateTime dtStartTime, DateTime dtEndTime, string strUserName, string strUserID, int intUserID, string strKeyID,string strCSKeyID)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@StartTime", SqlDbType.DateTime),
															 new SqlParameter("@EndTime", SqlDbType.DateTime),
															 new SqlParameter("@UserName", SqlDbType.NVarChar,1000),
															 new SqlParameter("@UserID", SqlDbType.VarChar,1000),
															 new SqlParameter("@CreateID", SqlDbType.Int),
															 new SqlParameter("@KeyID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@CS_KeyID", SqlDbType.UniqueIdentifier)};
			Guid guid = new Guid(strID);
			parameters[0].Value = guid;
			parameters[1].Value = dtStartTime;
			parameters[2].Value = dtEndTime;
			parameters[3].Value = strUserName;
			parameters[4].Value = strUserID;
			parameters[5].Value = intUserID;
			if (!(strKeyID != null ^ strKeyID != ""))
			{
				guid = new Guid(strKeyID);
				parameters[6].Value = guid;
			}
			else
			{
				parameters[6].Value = System.DBNull.Value;
			}

			if (!(strCSKeyID != null ^ strCSKeyID != ""))
			{
				guid = new Guid(strCSKeyID);
				parameters[7].Value = guid;
			}
			else
			{
				parameters[7].Value = System.DBNull.Value;
			}

			
			this.RunProcedure("sp_EmailAppoint_Update", parameters, "EmailAppoint");
		}
    }
}
